﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _4Gewinnt
{
    /// <summary>
    /// A game engine for 4gewinnt
    /// </summary>
    public abstract class Engine
    {

        /// <summary>
        /// The color of the engine
        /// </summary>
        public GameColor Me
        {
            get { return _me; }
        }
        /// <summary>
        /// The color of this engine
        /// </summary>
        protected GameColor _me;

        /// <summary>
        /// True, if engine is controlled via GUI
        /// </summary>
        public bool IsHuman
        {
            get { return _isHuman; }
        }
        /// <summary>
        /// True if this engine is controlled by a human
        /// </summary>
        protected bool _isHuman;

        /// <summary>
        /// Makes a move in the current situation
        /// </summary>
        /// <returns>The row number where to set a token</returns>
        public abstract int makeMove();
        
        /// <summary>
        /// Gets the move of the opponent
        /// </summary>
        /// <param name="c">The column where the opponent has moved</param>
        public abstract void update(int c);

        /// <summary>
        /// Called after each engine's turn. null means "nothing to say"
        /// </summary>
        /// <returns>A message a engine can send after each own turn</returns>
        public abstract String say();


        /// <summary>
        /// Creates a new instance of an engine of type <paramref name="type"/> using Reflection.
        /// The engine is constructed with a 1-parameter constructor taking GameColor
        /// <paramref name="color"/>, so each engine needs a constructor of this type
        /// </summary>
        /// <param name="type">The data type of the engine, i.e. typeof(EngineRandy) </param>
        /// <param name="color">The game color the engine gets assigned</param>
        /// <returns>A new instance of an engine of type <paramref name="type"/></returns>
        public static Engine Create(Type type, GameColor color)
        {
            return (Engine)(
                type
                    .GetConstructor(new Type[1] { typeof(GameColor) })
                    .Invoke(new Object[1] { color })
                    );
        }



    }
}
